/* the example on page 94 */

#include <gtk/gtk.h>
/* 准备材料，自定义函数  */
	/*  comments注释  */

/* 程序主体 */
int main( int argc, char *argv[] )
{
	GtkWidget *window;
	/* 声明变量window为构件gtkwidget */
	GtkWidget *hbox;
	GtkTextTag *tag1;
	GtkTextTag *tag2;
	GtkTextTag *tag3;
	GtkTextTag *tag4;
	GtkTextTag *tag5;
	GtkWidget *view1;
	GtkWidget *view2;
	GtkWidget *view3;
	GtkTextBuffer *buffer1;
	GtkTextBuffer *buffer2;
	GtkTextBuffer *buffer3;
	GtkTextIter iter;
	/* 注意iter前面是没有星号*的 */
	
	gtk_init (&argc, &argv);
	/* 初始化gtk */

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	/*  创建顶级窗口 */
	gtk_window_set_title (GTK_WINDOW (window), "三日诗three_days_verse");
	/*  为窗口顶部加上标题为三日诗three_days_verse  */
	g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL);
	/*  为窗口加上动作，当收到destroy信号，就启动gtk_main_quit事件，gtk_main_quit就是鼠标单击窗口右上角的关闭按钮就终止程序  */
	gtk_container_set_border_width (GTK_CONTAINER (window), 10);
	/*  简单的理解是将窗口变成容器，可以装入其它构件，构件边缘与窗口边缘的距离为100像数  */

	hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
	/*  创建组合框  */
	gtk_container_add (GTK_CONTAINER (window), hbox);
	/*  将组合框装入窗口容器  */
	
	view1 = gtk_text_view_new ();
	/*  创建文本显示构件 */
	gtk_box_pack_start (GTK_BOX (hbox), view1, FALSE, FALSE, 10);
	/*  将框架装入组合框容器中，数字10表示构件view1的边缘与hbox的边缘为10像数  */
	
	buffer1 = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view1));
	/*  创建缓冲区域，用来存储数据，并与构件view联系起来 */
	tag1 = gtk_text_buffer_create_tag (buffer1, NULL, "weight", PANGO_WEIGHT_BOLD, NULL);
	/*  创建格式标签tag1，意思是黑体 */
	tag2 = gtk_text_buffer_create_tag (buffer1, NULL, "scale", PANGO_SCALE_X_LARGE, NULL);
	/*  创建格式标签，意思是字体相对变大 */
	tag3 = gtk_text_buffer_create_tag (buffer1, NULL, "foreground", "red", NULL);
	/*  创建格式标签，意思是字体颜色为红色 */
	tag4 = gtk_text_buffer_create_tag (buffer1, NULL, "background", "gray", NULL);
	/*  创建格式标签，意思是背景为暗灰色 */
	tag5 = gtk_text_buffer_create_tag (buffer1, NULL, "underline", PANGO_UNDERLINE_SINGLE, NULL);
	/*  创建格式标签，意思是下划线 */
	
	gtk_text_buffer_get_iter_at_offset (buffer1, &iter, 0);
	/*  初始化缓冲区域 */
	gtk_text_buffer_insert_with_tags (buffer1, &iter, "昨日诗\n", -1, tag1, tag2, NULL);
	/*  创建一个新行并写入数据，格式为黑体和变大，-1表示数据的结尾，NULL表示格式项的结尾 */
	gtk_text_buffer_insert (buffer1, &iter, "昨日兮昨日，\n", -1);
	gtk_text_buffer_insert (buffer1, &iter, "昨日何其好！\n", -1);
	gtk_text_buffer_insert (buffer1, &iter, "昨日过去了，\n", -1);
	gtk_text_buffer_insert (buffer1, &iter, "今日徒懊恼。\n", -1);
	gtk_text_buffer_insert_with_tags (buffer1, &iter, "世人但知悔昨日，\n", -1, tag4, NULL);
	/*  创建一个新行并写入数据，格式为背景色为暗灰色，-1表示数据的结尾，NULL表示格式项的结尾 */
	gtk_text_buffer_insert_with_tags (buffer1, &iter, "不觉今日又过了。\n", -1, tag4, NULL);
	gtk_text_buffer_insert (buffer1, &iter, "水去日日流，\n", -1);
	gtk_text_buffer_insert (buffer1, &iter, "花落日日少，\n", -1);
	gtk_text_buffer_insert_with_tags (buffer1, &iter, "成事立业在今日，\n", -1, tag3, tag5, NULL);
	gtk_text_buffer_insert_with_tags (buffer1, &iter, "莫待明朝悔今朝。\n", -1, tag3, tag5, NULL);


	view2 = gtk_text_view_new ();
	gtk_box_pack_start (GTK_BOX (hbox), view2, FALSE, FALSE, 10);
	buffer2 = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view2));
	tag1 = gtk_text_buffer_create_tag (buffer2, NULL, "weight", PANGO_WEIGHT_BOLD, NULL);
	tag2 = gtk_text_buffer_create_tag (buffer2, NULL, "scale", PANGO_SCALE_X_LARGE, NULL);
	tag3 = gtk_text_buffer_create_tag (buffer2, NULL, "foreground", "red", NULL);
	tag4 = gtk_text_buffer_create_tag (buffer2, NULL, "background", "gray", NULL);
	tag5 = gtk_text_buffer_create_tag (buffer2, NULL, "underline", PANGO_UNDERLINE_SINGLE, NULL);
	gtk_text_buffer_get_iter_at_offset (buffer2, &iter, 0);
	gtk_text_buffer_insert_with_tags (buffer2, &iter, "今日诗\n", -1, tag1, tag2, NULL);
	gtk_text_buffer_insert (buffer2, &iter, "今日复今日，\n", -1);
	gtk_text_buffer_insert (buffer2, &iter, "今日何其少！\n", -1);
	gtk_text_buffer_insert (buffer2, &iter, "今日又不为，\n", -1);
	gtk_text_buffer_insert (buffer2, &iter, "此事何时了。\n", -1);
	gtk_text_buffer_insert_with_tags (buffer2, &iter, "人生百年几今日，\n", -1, tag4, NULL);
	gtk_text_buffer_insert_with_tags (buffer2, &iter, "今日不为真可惜！\n", -1, tag4, NULL);
	gtk_text_buffer_insert (buffer2, &iter, "若言姑待明朝至，\n", -1);
	gtk_text_buffer_insert (buffer2, &iter, "明朝又有明朝事。\n", -1);
	gtk_text_buffer_insert_with_tags (buffer2, &iter, "为君聊赋今日诗，\n", -1, tag3, tag5, NULL);
	gtk_text_buffer_insert_with_tags (buffer2, &iter, "努力请从今日始。\n", -1, tag3, tag5, NULL);

	view3 = gtk_text_view_new ();
	gtk_box_pack_start (GTK_BOX (hbox), view3, FALSE, FALSE, 10);
	buffer3 = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view3));
	tag1 = gtk_text_buffer_create_tag (buffer3, NULL, "weight", PANGO_WEIGHT_BOLD, NULL);
	tag2 = gtk_text_buffer_create_tag (buffer3, NULL, "scale", PANGO_SCALE_X_LARGE, NULL);
	tag3 = gtk_text_buffer_create_tag (buffer3, NULL, "foreground", "red", NULL);
	tag4 = gtk_text_buffer_create_tag (buffer3, NULL, "background", "gray", NULL);
	tag5 = gtk_text_buffer_create_tag (buffer3, NULL, "underline", PANGO_UNDERLINE_SINGLE, NULL);
	gtk_text_buffer_get_iter_at_offset (buffer3, &iter, 0);
	gtk_text_buffer_insert_with_tags (buffer3, &iter, "明日诗\n", -1, tag1, tag2, NULL);
	gtk_text_buffer_insert (buffer3, &iter, "明日复明日，\n", -1);
	gtk_text_buffer_insert (buffer3, &iter, "明日何其多！\n", -1);
	gtk_text_buffer_insert (buffer3, &iter, "我生待明日，\n", -1);
	gtk_text_buffer_insert (buffer3, &iter, "万事成蹉跎。\n", -1);
	gtk_text_buffer_insert_with_tags (buffer3, &iter, "世人皆被明日累，\n", -1, tag4, NULL);
	gtk_text_buffer_insert_with_tags (buffer3, &iter, "春去秋来老将至。\n", -1, tag4, NULL);
	gtk_text_buffer_insert (buffer3, &iter, "朝看水去流，\n", -1);
	gtk_text_buffer_insert (buffer3, &iter, "暮看日西坠，\n", -1);
	gtk_text_buffer_insert_with_tags (buffer3, &iter, "百年明日能几何？\n", -1, tag3, tag5, NULL);
	gtk_text_buffer_insert_with_tags (buffer3, &iter, "请君听我明日歌。\n", -1, tag3, tag5, NULL);

	gtk_widget_show_all (window);
	/*  显示构件窗口包括所有构件  */
	gtk_main ();
	/*  进入主循环，等待信号（鼠标键盘）输入  */
	return 0;
}
/* gcc pageXX.c -o pageXX `pkg-config --cflags --libs gtk+-3.0` */
